﻿using System;

namespace NDBGen
{
    public struct TableKey
    {
        public TableKey(String schemaName, String tableName)
            : this()
        {
            this.SchemaName = schemaName;
            this.TableName = tableName;
        }

        public String TableName { get; private set; }

        public String SchemaName { get; private set; }

        public String TypeName { get { return this.TableName.Depluralize().ToPascalCase(); } }
        public String NamespaceName { get { return this.SchemaName.ToPascalCase(); } }

        public static Boolean operator ==(TableKey a, TableKey b)
        {
            return a.Equals(b);
        }

        public static Boolean operator !=(TableKey a, TableKey b)
        {
            return !a.Equals(b);
        }

        public override Boolean Equals(Object obj)
        {
            if (obj is TableKey)
            {
                var that = (TableKey)obj;

                return
                    this.TableName == that.TableName &&
                    this.SchemaName == that.SchemaName;
            }
            else return false;
        }

        public override Int32 GetHashCode()
        {
            return
                this.SchemaName.GetHashCode() ^
                this.TableName.GetHashCode();
        }

        public override String ToString()
        {
            return String.Format("{0}.{1}", this.SchemaName, this.TableName);
        }
    }
}